package com.berwin.bmfb.views.components;

import com.berwin.bmfb.entity.BMChar;
import com.berwin.bmfb.entity.BMFont;

import javax.swing.*;
import java.awt.*;

public class DrawLetterView extends JPanel {

    private BMChar bmChar = null;
    private boolean isNeedCenter = false;

    public DrawLetterView(BMChar bmChar) {
        this.bmChar = bmChar;
        this.setBackground(Color.BLACK);
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        if (this.bmChar == null)
            return;
        if (isNeedCenter) {
            int x = (this.getSize().width - this.bmChar.getWidth()) / 2;
            int y = (this.getSize().height - this.bmChar.getHeight()) / 2;
            g.drawImage(this.bmChar.getImage(), x, y, x + this.bmChar.getWidth(), y + this.bmChar.getHeight(), 0, 0, this.bmChar.getWidth(), this.bmChar.getHeight(), null);
        } else {
            g.drawImage(this.bmChar.getImage(), 0, 0, this.bmChar.getWidth(), this.bmChar.getHeight(), 0, 0, this.bmChar.getWidth(), this.bmChar.getHeight(), null);
        }
    }

    public void updateBMChar(BMChar bmChar) {
        this.bmChar = bmChar;
        this.repaint();
    }

    public BMChar getBmChar() {
        return bmChar;
    }

    public void setBmChar(BMChar bmChar) {
        this.bmChar = bmChar;
    }

    public boolean isNeedCenter() {
        return isNeedCenter;
    }

    public void setNeedCenter(boolean needCenter) {
        isNeedCenter = needCenter;
    }
}
